package com.good.child.pressent;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;

import com.good.child.bean.common.AppVersion;
import com.good.child.http.CommonLogical;
import com.good.child.http.LoginLogical;
import com.good.child.iview.MainIView;
import com.good.child.ui.utils.CommonU;
import com.good.child.widgets.dialog.AppUpdateFragment;
import com.yimidida.library.base.BaseActivity;
import com.yimidida.library.base.BasePresenter;
import com.yimidida.library.base.BaseView;
import com.yimidida.library.base.ICallBackResultListener;
import com.yimidida.library.utils.LogUtils;
import com.yimidida.library.utils.ToastUtil;

/**
 * Create on: 2024/2/27
 * by Mr.Zhu
 * Description: TODO
 */
public class MainPresenter extends BasePresenter<MainIView>{

    private BaseActivity mContext;

    public MainPresenter(BaseActivity mContext) {
        this.mContext = mContext;
    }


    public void checkUpdate(boolean showTips) {
        CommonLogical.getInstance().requestUpdateApp(null, new ICallBackResultListener() {
            @Override
            public void onCallBack(Object result) {
                if (result == null) {
                    return;
                }
                AppVersion appVersion = (AppVersion) result;
                int serverVersion = 0;
                if (!TextUtils.isEmpty(appVersion.getClientVersion())) {
                    serverVersion = Integer.parseInt(appVersion.getClientVersion());
                }
                int versionCode = CommonU.getVersionCode(mContext);
                LogUtils.showLog("zhu","当前版本 = "+ versionCode +"  服务器版本 = "+ serverVersion);
                if (serverVersion <= versionCode) {
//                    SharePreferenceUitls.remove(getActivity(), AppVersionUpdatePresenter.LAST_REQUEST_TIME);
//                    SharePreferenceUitls.remove(getActivity(), AppVersionUpdatePresenter.IS_FORCE_UPDATE);
//                ToastUtils.ToastShortCenter(getActivity(), getActivity().getString(R.string.str_new_version));
                    if (showTips) {
                        ToastUtil.showShort("已是最新版本");
                    }
                    return;
                }
                AppUpdateFragment.show(mContext.getSupportFragmentManager(), appVersion);
            }
        });
    }


    public void updateLocation(String longitude,String latitude) {

    }
}
